package com.tanhua.server.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.tanhua.dubbo.api.BlackListApi;
import com.tanhua.model.domain.UserInfo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.server.intercepter.UserThreadLocal;
import com.tanhua.server.service.BlackService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

@Service
public class BlackServiceImpl implements BlackService {

    @DubboReference
    private BlackListApi blackListApi;

    //获取黑名单用户
    @Override
    public PageResult findPage(int page, int pageSize) {

        //1.获取用户id
        Long userId = UserThreadLocal.getUserId();
        //2.调用api查询黑名单的分页列表数据
        IPage<UserInfo> listIPage = blackListApi.findBlackByPage(userId, page, pageSize);

        //3.转为pageResult
        PageResult pr = new PageResult(page, pageSize,
                listIPage.getTotal(), listIPage.getRecords());
        return pr;
    }

    //移出黑名单
    @Override
    public void deleteBlackUser(Long blackId) {
        //1.获取当前用户id
        Long userId = UserThreadLocal.getUserId();
        //调用api删除
        blackListApi.deleteBlackList(userId,blackId);
    }
}
